package cheme.ProcessEditor.Figures.Util;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Locator;
import org.eclipse.draw2d.geometry.Rectangle;

public class ChemeLocator implements Locator
{
	IFigure host = null;
	PositionCalculator.RelativePosition position;
	
	public ChemeLocator(IFigure host, PositionCalculator.RelativePosition position)
	{
		this.host = host;
		this.position = position;
	}
	
	public void relocate(IFigure target)
	{
		Rectangle targetRect = new Rectangle(target.getBounds().getTopLeft(), target.getPreferredSize());
		target.translateToAbsolute(targetRect);
		
		Rectangle hostRect = new Rectangle(host.getBounds().getTopLeft(), host.getPreferredSize());
		host.translateToAbsolute(hostRect);
		
		targetRect = PositionCalculator.getRelativeRectangle(hostRect, targetRect, position);
		target.translateToParent(targetRect);
		target.setBounds(targetRect);
	}
}